package cn.tedu.luban.demand.main.repository.impl;

import cn.tedu.luban.demand.main.converter.DemandConverter;
import cn.tedu.luban.demand.main.dao.DemandDAO;
import cn.tedu.luban.demand.main.repository.DemandRepository;
import cn.tedu.luban.demand.protocol.bo.RequestOrderBO;
import cn.tedu.luban.demand.protocol.dos.RequestOrderDO;
import cn.tedu.luban.demand.protocol.param.GrabOrderParam;
import cn.tedu.luban.demand.protocol.query.RequestOrderDBPagerQuery;
import cn.tedu.luban.demand.protocol.query.RequestOrderQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public class DemandRepositoryImpl implements DemandRepository {

    @Autowired
    private DemandConverter demandConverter;

    @Autowired
    private DemandDAO demandDAO;

    //查询分页条件总数
    @Override
    public Long getRequestOrderCount(RequestOrderQuery requestOrderQuery) {
        RequestOrderDBPagerQuery requestOrderDBPagerQuery = demandConverter.toDbPagerQuery(requestOrderQuery);
        return demandDAO.countRequestOrder(requestOrderDBPagerQuery);
    }

    //查询分页条件的list
    @Override
    public List<RequestOrderBO> queryRequestOrders(RequestOrderQuery requestOrderQuery) {
        RequestOrderDBPagerQuery requestOrderDBPagerQuery = demandConverter.toDbPagerQuery(requestOrderQuery);
        List<RequestOrderDO> requestOrderDOS = demandDAO.queryRequestOrders(requestOrderDBPagerQuery);
        //UserVO  UserView
        return demandConverter.poList2BoList(requestOrderDOS);
    }

    @Override
    public Integer grabOrder(GrabOrderParam grabOrderParam) {

        return demandDAO.grabOrder(grabOrderParam.getRequestOrderNO());
    }

    @Override
    public RequestOrderBO getRequestOrder(String requestOrderNo) {
        return null;
    }

    @Override
    public Integer returnOrder(GrabOrderParam grabOrderParam) {
        return demandDAO.returnOrder(grabOrderParam);
    }

    @Override
    public RequestOrderBO getRequestOrderGrabed(String no) {
        return null;
    }
}
